package com.ruoyi.web.controller.qsng;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.qsng.domain.KUsers;
import com.ruoyi.qsng.service.IKUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户信息Controller
 *
 * @author kanglou
 * @date 2023-06-07
 */
@RestController
@RequestMapping("/qsng/users")
@Api(tags = "pc--用户信息Controller")
public class KUsersController extends BaseController {
    @Autowired
    private IKUsersService kUsersService;

    /**
     * 查询用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:users:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询用户信息列表")
    public TableDataInfo list(KUsers kUsers) {
        startPage();
        List<KUsers> list = kUsersService.selectKUsersList(kUsers);
        return getDataTable(list);
    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('qsng:users:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出用户信息列表")
    public void export(HttpServletResponse response, KUsers kUsers) {
        List<KUsers> list = kUsersService.selectKUsersList(kUsers);
        ExcelUtil<KUsers> util = new ExcelUtil<KUsers>(KUsers.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:users:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取用户信息详细信息")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(kUsersService.selectKUsersById(id));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:users:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增用户信息")
    public AjaxResult add(@RequestBody KUsers kUsers) {
        return toAjax(kUsersService.insertKUsers(kUsers));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:users:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改用户信息")
    public AjaxResult edit(@RequestBody KUsers kUsers) {
        return toAjax(kUsersService.updateKUsers(kUsers));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('qsng:users:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除用户信息")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(kUsersService.deleteKUsersByIds(ids));
    }
}
